<?php
namespace Admin\Controller;

use Util\AccessController;


class TgActivityController extends AccessController {

    public function index() {
        $LS = Service('M', 'tg_activity');
        $DATA = $LS->query();
        $this->DATA = $DATA;
        $this->display();
    }

    public function handle() {
        $save = $_POST;
        $save['A_CREATE_TIME'] = date('Y-m-d H:i:s');
        $LS = Service('M', 'tg_activity');
        if($_POST['ID']){
            $OK = $LS->update(array('ID'=>$_POST['ID']),$save);
        }else{
            $OK = $LS->Add($save);
        }
        $OK ? $this->success('添加成功') : $this->error('添加失败');


    }

    public function changeState() {
        $LS = Service('M', 'tg_activity');
        $data = $LS->find(array('STATE' => 1));
//        if ($data && $_POST['STATE']==1) {
//            echo -1;
//        } else {
        $where['ID'] = $_POST['ID'];
        $save['STATE'] = $_POST['STATE'];
        $OK = $LS->update($where, $save);
        echo $OK;
//        }
    }

    public function Del(){
        $LS = Service('M', 'tg_activity');
        $where['ID'] = $_POST['ID'];
        $OK = $LS->Del($where);
        echo $OK;
    }


}